<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="utf-8">
<!-- build.cpp -->
  <title>Qt for OpenHarmony编译指导 | Qt for OpenHarmony</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
            <li><a href="aboutqt.html">Qt 5.15.12</a></li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3 id="toc">Contents</h3>
<ul>
<li class="level1"><a href="#qt-for-openharmony-28e38370"><b>获取 Qt for OpenHarmony 源代码</b></a></li>
<li class="level1"><a href="#6ddfeb00"><b>系统环境要求</b></a></li>
<li class="level2"><a href="#windows-linux-mac-6378a287"><b>所有的桌面平台（Windows、Linux、Mac）</b></a></li>
<li class="level1"><a href="#windows-openharmony-qt-f12a051c"><b>在 Windows 中为 OpenHarmony 构建 Qt 库</b></a></li>
<li class="level2"><a href="#b6cc125c"><b>配置构建环境</b></a></li>
<li class="level2"><a href="#qt-for-openharmony-59ae5410"><b>构建 Qt for OpenHarmony</b></a></li>
<li class="level2"><a href="#7b166c7f"><b>完整构建脚本参考</b></a></li>
<li class="level1"><a href="#macos-openharmony-qt-97e46647"><b>在 macOS 中为 OpenHarmony 构建 Qt 库</b></a></li>
<li class="level2"><a href="#macos-openharmony-qt-97e46647-b6cc125c-8"><b>配置构建环境</b></a></li>
<li class="level2"><a href="#macos-openharmony-qt-97e46647-qt-for-openharmony-59ae5410-9"><b>构建 Qt for OpenHarmony</b></a></li>
<li class="level2"><a href="#macos-openharmony-qt-97e46647-7b166c7f-10"><b>完整构建脚本参考</b></a></li>
<li class="level1"><a href="#linux-qt-for-openharmony-qt-52063c09"><b>在 Linux 中为 Qt for OpenHarmony 构建 Qt 库</b></a></li>
<li class="level2"><a href="#linux-qt-for-openharmony-qt-52063c09-b6cc125c-12"><b>配置构建环境</b></a></li>
<li class="level2"><a href="#linux-qt-for-openharmony-qt-52063c09-qt-for-openharmony-59ae5410-13"><b>构建 Qt for OpenHarmony</b></a></li>
<li class="level2"><a href="#linux-qt-for-openharmony-qt-52063c09-7b166c7f-14"><b>完整构建脚本参考</b></a></li>
<li class="level1"><a href="#qt-c585cfc6"><b>查阅更多编译配置信息，请参阅Qt官方文档</b></a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt for OpenHarmony编译指导</h1>
<!-- $$$build-qt-for-openharmony.html-description -->
<div class="descr" id="details">
<p>若您有需要从源代码构建Qt for Harmony的特定版本或进行源码修改以适配您的项目需求，请访问 <a href="http://qt.isscloud.com:8800/qt-for-harmony/qt5.git">Qt for Harmony Git</a>获取完整源代码。</p>
<h2 id="qt-for-openharmony-28e38370"><b>获取 Qt for OpenHarmony 源代码</b></h2>
<ol class="1" type="1"><li>登录Qt for OpenHarmony Git仓库, <a href="http://qt.isscloud.com:8800">http://qt.isscloud.com:8800</a>。</li>
<li>访问 <a href="http://qt.isscloud.com:8800/qt-for-harmony/qt5.git">http://qt.isscloud.com:8800/qt-for-harmony/qt5.git</a>，请参考以下命令进行代码仓库克隆操作。<pre class="cpp" translate="no">
 git clone http:<span class="comment">//qt.isscloud.com:8800/qt-for-harmony/qt5 ./qt5</span>
</pre>
</li>
<li>进入克隆的源码目录并切换至 <a href="http://qt.isscloud.com:8800/qt-for-harmony/qt5/-/tree/5.15.12-ohos-next">5.15.12-ohos-next</a>分支<pre class="cpp" translate="no">
 cd qt5
 git <span class="keyword">switch</span> <span class="number">5.15.12</span><span class="operator">-</span>ohos<span class="operator">-</span>next
 <span class="preprocessor">#对于较旧版本的git，可能需要执行以下命令切换分支</span>
 git checkout <span class="number">5.15.12</span><span class="operator">-</span>ohos<span class="operator">-</span>next
</pre>
</li>
<li>更新子模块<pre class="cpp" translate="no">
 git submodule update <span class="operator">-</span><span class="operator">-</span>progress <span class="operator">-</span><span class="operator">-</span>init <span class="operator">-</span><span class="operator">-</span>recursive <span class="operator">-</span><span class="operator">-</span>remote
</pre>
</li>
</ol>
<h2 id="6ddfeb00"><b>系统环境要求</b></h2>
<h3 id="windows-linux-mac-6378a287"><b>所有的桌面平台（Windows、Linux、Mac）</b></h3>
<ul>
<li><a href="https://git-scm.com">Git</a> (&gt;= 1.6.x)</li>
<li><a href="https://download.qt.io/development_releases/prebuilt/perl">Perl</a> (&gt;=5.14)</li>
<li><a href="https://www.python.org/downloads/release/python-2718">Python</a> (&gt;=2.6.x)</li>
<li>可以工作的编译器<p>Windows: MinGW ,Linux/Mac: make</p>
<div class="admonition note">
<p><b>Note: </b>虽然Qt 5.15.x在技术规格上支持GCC 11.x版本，但实际编译过程中可能出现兼容性问题。 为确保构建过程的稳定性和可靠性，建议选择GCC 5.3至9.x版本作为编译环境。 这将有助于避免潜在的编译错误并保证系统的整体兼容性。</p>
</div>
</li>
<li><a href="https://developer.huawei.com/consumer/cn/download">OpenHarmony SDK</a><p>对于安装了DevEco Studio的用户，OpenHarmony SDK位于&lt;DevEco Studio Path&gt;/sdk/default/openharmony目录下。 您也可以选择下载Command Line Tools命令行工具包，并使用该工具包中提供的SDK，其位置为&lt;Command Line Tools Path&gt;/sdk/default/openharmony。</p>
<div class="admonition note">
<p><b>Note: </b>DevEco Studio默认安装路径为&lt;C:/Program Files/Huawei/DevEco Studio&gt;，该路径包含空格。 请注意，编译工具路径不应包含空格、中文或特殊字符，开发者在配置编译环境时需谨慎设置，以避免潜在的编译错误。</p>
</div>
</li>
<li>SSL 支持（可选项），如需访问OpenSSL开发文件，请访问： <a href="https://gitee.com/openharmony/third_party_openssl/tree/master/include/openssl">https://gitee.com/openharmony/third_party_openssl/tree/master/include/openssl</a>。</li>
</ul>
<h2 id="windows-openharmony-qt-f12a051c"><b>在 Windows 中为 OpenHarmony 构建 Qt 库</b></h2>
<h3 id="b6cc125c"><b>配置构建环境</b></h3>
<p>您可以将MinGW和Perl的路径添加至系统PATH环境变量中，以便系统能够识别这些程序。 请通过以下步骤操作：右键开始菜单→系统→高级系统设置→环境变量，然后在&quot;系统变量&quot;列表中编辑Path变量。</p>
<p class="centerAlign"><img src="images/set-strawberry-path.png" alt="" /></p><p>或者，您也可以创建一个环境配置脚本来设置临时环境变量，具体如下：</p>
<pre class="cpp" translate="no">
 set MINGW_PATH<span class="operator">=</span>C:\build<span class="operator">-</span>tools\mingw64\bin

 set PATH<span class="operator">=</span><span class="operator">%</span>PATH<span class="operator">%</span>;<span class="operator">%</span>MINGW_PATH<span class="operator">%</span>
 set PATH<span class="operator">=</span><span class="operator">%</span>PATH<span class="operator">%</span>;C:\build<span class="operator">-</span>tools\Strawberry\perl\bin
</pre>
<p>下载OpenHarmony SDK并配置OpenHarmony SDK环境变量，以便找到llvm工具、SDK头文件和库。 在&quot;系统变量&quot;列表中新建OHOS_SDK_PATH变量，并将值设置为&lt;DevEco Studio Path&gt;|&lt;Command Line Tools Path&gt;/sdk/default/openharmony ， 注意其中的&lt;DevEco Studio Path&gt;|&lt;Command Line Tools Path&gt; 需要更换为SDK实际路径。</p>
<p class="centerAlign"><img src="images/set-oh-sdk-path.png" alt="" /></p><p>或者，您也可以创建一个环境配置脚本来设置临时环境变量，具体如下：</p>
<pre class="cpp" translate="no">
 set OHOS_SDK_PATH<span class="operator">=</span>C:\build<span class="operator">-</span>tools\command<span class="operator">-</span>line<span class="operator">-</span>tools\sdk\<span class="keyword">default</span>\openharmony
</pre>
<p>以下为目前尚未完成 OpenHarmony 平台适配的模块，需要在编译时排除：</p>
<pre class="cpp" translate="no">
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtpim
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtconnectivity
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtvirtualkeyboard
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtwebengine
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtsystems
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtlocation
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtgamepad
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtscript
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtsensors
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtwebview
</pre>
<p>配置编译参数：</p>
<pre class="cpp" translate="no">
 @REM 引用之前设置的临时环境变量SKIP_MODULES
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>opensource <span class="operator">-</span>confirm<span class="operator">-</span>license
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>platform win32<span class="operator">-</span>g<span class="operator">+</span><span class="operator">+</span> <span class="operator">-</span>xplatform oh<span class="operator">-</span>clang
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>opengl es2 <span class="operator">-</span>opengles3 <span class="operator">-</span>no<span class="operator">-</span>dbus
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>device<span class="operator">-</span>option OHOS_ARCH<span class="operator">=</span>arm64<span class="operator">-</span>v8a
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>nomake tests <span class="operator">-</span>nomake examples
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span>
</pre>
<div class="admonition note">
<p><b>Note: </b>OHOS_ARCH=armeabi-v7a会编译32位Qt库，OHOS_ARCH=arm64-v8a会编译64位Qt库，OHOS_ARCH=x86-64会编译x86_64Qt库。</p>
</div>
<p>启用fontconfig支持，需要准备fontconfig库及其相关头文件：（此项为可选配置）</p>
<pre class="cpp" translate="no">
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>fontconfig <span class="operator">-</span>I <span class="string">&quot;C:\build-tools\fontconfig\include&quot;</span> <span class="operator">-</span>L <span class="string">&quot;C:\build-tools\fontconfig\libs&quot;</span>
</pre>
<p>启用openssl支持，需要准备openssl相关头文件：（此项为可选配置）</p>
<pre class="cpp" translate="no">
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>openssl<span class="operator">-</span>runtime OPENSSL_INCDIR<span class="operator">=</span><span class="string">&quot;C:\build-tools\openssl\include&quot;</span>
</pre>
<h3 id="qt-for-openharmony-59ae5410"><b>构建 Qt for OpenHarmony</b></h3>
<ol class="1" type="1"><li>打开命令行工具，进入Qt for OpenHarmony源码目录。<pre class="cpp" translate="no">
 cd qt5
</pre>
</li>
<li>创建构建目录,进入构建目录<pre class="cpp" translate="no">
 mkdir build <span class="operator">&amp;</span><span class="operator">&amp;</span> cd build
</pre>
</li>
<li>运行以下命令，开始构建Qt for OpenHarmony。<pre class="cpp" translate="no">
 @REM 执行配置脚本，引用之前设置的临时环境变量<span class="operator">%</span>build_options<span class="operator">%</span>

 <span class="operator">.</span><span class="operator">.</span>\configure <span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>prefix C:<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="number">5.15.12</span><span class="operator">/</span>ohos18_arm64<span class="operator">-</span>v8a <span class="operator">-</span>recheck<span class="operator">-</span>all
 mingw32<span class="operator">-</span>make <span class="operator">-</span>j<span class="operator">%</span>{NUMBER_OF_PROCESSORS}<span class="operator">%</span> <span class="operator">&amp;</span><span class="operator">&amp;</span> mingw32<span class="operator">-</span>make install
</pre>
<div class="admonition note">
<p><b>Note: </b>该命令启用多线程编译功能，其中NUMBER_OF_PROCESSORS变量表示系统支持的最大线程数。该变量已在系统环境中预设，您可根据实际需求调整线程数。</p>
</div>
</li>
<li>编译完成后，Qt for OpenHarmony将安装在指定的路径`C:/Qt/5.15.12/ohos18_arm64-v8a`下</li>
</ol>
<h3 id="7b166c7f"><b>完整构建脚本参考</b></h3>
<pre class="cpp" translate="no">
 @echo off
 set MINGW_PATH<span class="operator">=</span>C:\build<span class="operator">-</span>tools\mingw64\bin
 set PATH<span class="operator">=</span><span class="operator">%</span>PATH<span class="operator">%</span>;<span class="operator">%</span>MINGW_PATH<span class="operator">%</span>
 set PATH<span class="operator">=</span><span class="operator">%</span>PATH<span class="operator">%</span>;C:\build<span class="operator">-</span>tools\Strawberry\perl\bin

 set OHOS_SDK_PATH<span class="operator">=</span>C:\build<span class="operator">-</span>tools\command<span class="operator">-</span>line<span class="operator">-</span>tools\sdk\<span class="keyword">default</span>\openharmony

 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtpim
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtconnectivity
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtvirtualkeyboard
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtwebengine
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtsystems
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtlocation
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtgamepad
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtscript
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtsensors
 set SKIP_MODULES<span class="operator">=</span><span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span> <span class="operator">-</span>skip qtwebview

 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>opensource <span class="operator">-</span>confirm<span class="operator">-</span>license
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>platform win32<span class="operator">-</span>g<span class="operator">+</span><span class="operator">+</span> <span class="operator">-</span>xplatform oh<span class="operator">-</span>clang
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>opengl es2 <span class="operator">-</span>opengles3 <span class="operator">-</span>no<span class="operator">-</span>dbus
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>device<span class="operator">-</span>option OHOS_ARCH<span class="operator">=</span>arm64<span class="operator">-</span>v8a
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>nomake tests <span class="operator">-</span>nomake examples
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>fontconfig <span class="operator">-</span>I <span class="string">&quot;C:\build-tools\fontconfig\include&quot;</span> <span class="operator">-</span>L <span class="string">&quot;C:\build-tools\fontconfig\libs&quot;</span>
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>openssl<span class="operator">-</span>runtime OPENSSL_INCDIR<span class="operator">=</span><span class="string">&quot;C:\build-tools\openssl\include&quot;</span>
 set BUILD_OPTIONS<span class="operator">=</span><span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">%</span>{SKIP_MODULES}<span class="operator">%</span>

 cd qt5
 mkdir build <span class="operator">&amp;</span><span class="operator">&amp;</span> cd build
 <span class="operator">.</span><span class="operator">.</span>\configure <span class="operator">%</span>{BUILD_OPTIONS}<span class="operator">%</span> <span class="operator">-</span>prefix C:<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="number">5.15.12</span><span class="operator">/</span>ohos18_arm64<span class="operator">-</span>v8a <span class="operator">-</span>recheck<span class="operator">-</span>all
 mingw32<span class="operator">-</span>make <span class="operator">-</span>j<span class="operator">%</span>{NUMBER_OF_PROCESSORS}<span class="operator">%</span> <span class="operator">&amp;</span><span class="operator">&amp;</span> mingw32<span class="operator">-</span>make install
</pre>
<h2 id="macos-openharmony-qt-97e46647"><b>在 macOS 中为 OpenHarmony 构建 Qt 库</b></h2>
<h3 id="macos-openharmony-qt-97e46647-b6cc125c-8"><b>配置构建环境</b></h3>
<p>从 App Store 安装 Xcode</p>
<p>下载OpenHarmony SDK并配置OpenHarmony SDK环境变量，以便找到llvm工具、SDK头文件和库。 在终端中输入以下命令，设置环境变量：</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> OHOS_SDK_PATH<span class="operator">=</span><span class="operator">/</span>Users<span class="operator">/</span><span class="operator">&lt;</span>username<span class="operator">&gt;</span><span class="operator">/</span>Library<span class="operator">/</span>command<span class="operator">-</span>line<span class="operator">-</span>tools<span class="operator">/</span>sdk<span class="operator">/</span><span class="keyword">default</span><span class="operator">/</span>openharmony
</pre>
<p>以下为目前尚未完成 OpenHarmony 平台适配的模块，需要在编译时排除：</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtpim&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtconnectivity&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtvirtualkeyboard&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtwebengine&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsystems&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtlocation&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtgamepad&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtscript&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsensors&quot;</span>
 <span class="keyword">export</span> skip_modules<span class="operator">=</span><span class="string">&quot;${skip_modules} -skip qtwebview&quot;</span>
</pre>
<p>配置编译参数：</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opensource -confirm-license&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -platform macx-clang -xplatform oh-clang&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opengl es2 -opengles3 -no-dbus&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -device-option OHOS_ARCH=arm64-v8a&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -nomake tests -nomake examples&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} ${SKIP_MODULES}&quot;</span>
</pre>
<div class="admonition note">
<p><b>Note: </b>OHOS_ARCH=armeabi-v7a会编译32位Qt库，OHOS_ARCH=arm64-v8a会编译64位Qt库，OHOS_ARCH=x86-64会编译x86_64Qt库。</p>
</div>
<p>启用fontconfig支持，需要准备fontconfig库及其相关头文件：（此项为可选配置）</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span>${BUILD_OPTIONS} <span class="operator">-</span>fontconfig <span class="operator">-</span>I <span class="string">&quot;/Users/&lt;username&gt;/Library/fontconfig/include&quot;</span> <span class="operator">-</span>L <span class="string">&quot;/Users/&lt;username&gt;/Library/fontconfig/libs&quot;</span>
</pre>
<p>启用openssl支持，需要准备openssl相关头文件：（此项为可选配置）</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span>${BUILD_OPTIONS} <span class="operator">-</span>openssl<span class="operator">-</span>runtime OPENSSL_INCDIR<span class="operator">=</span><span class="string">&quot;/Users/&lt;username&gt;/Library/openssl/include&quot;</span>
</pre>
<h3 id="macos-openharmony-qt-97e46647-qt-for-openharmony-59ae5410-9"><b>构建 Qt for OpenHarmony</b></h3>
<ol class="1" type="1"><li>打开终端，进入Qt for OpenHarmony源码目录。<pre class="cpp" translate="no">
 cd qt5
</pre>
</li>
<li>创建构建目录,进入构建目录<pre class="cpp" translate="no">
 mkdir build <span class="operator">&amp;</span><span class="operator">&amp;</span> cd build
</pre>
</li>
<li>运行以下命令，开始构建Qt for OpenHarmony。<pre class="cpp" translate="no">
 <span class="preprocessor"># 执行配置脚本，引用之前设置的临时环境变量${BUILD_OPTIONS}</span>

 <span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>configure ${BUILD_OPTIONS} <span class="operator">-</span>prefix <span class="operator">/</span>Users<span class="operator">/</span><span class="operator">&lt;</span>username<span class="operator">&gt;</span><span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="number">5.15.12</span><span class="operator">/</span>ohos18_arm64<span class="operator">-</span>v8a <span class="operator">-</span>recheck<span class="operator">-</span>all
 make <span class="operator">-</span>j$(sysctl <span class="operator">-</span>n hw<span class="operator">.</span>ncpu) <span class="operator">&amp;</span><span class="operator">&amp;</span> make install
</pre>
<div class="admonition note">
<p><b>Note: </b>该命令启用多线程编译功能，其中`$(sysctl -n hw.ncpu)`变量表示系统支持的最大线程数。您可根据实际需求调整线程数。</p>
</div>
</li>
<li>编译完成后，Qt for OpenHarmony将安装在指定的路径`/Users/&lt;username&gt;/Qt/5.15.12/ohos18_arm64-v8a`下</li>
</ol>
<h3 id="macos-openharmony-qt-97e46647-7b166c7f-10"><b>完整构建脚本参考</b></h3>
<pre class="cpp" translate="no">
 <span class="preprocessor">#!/bin/bash</span>
 <span class="keyword">export</span> OHOS_SDK_PATH<span class="operator">=</span><span class="operator">/</span>Users<span class="operator">/</span><span class="operator">&lt;</span>username<span class="operator">&gt;</span><span class="operator">/</span>Library<span class="operator">/</span>command<span class="operator">-</span>line<span class="operator">-</span>tools<span class="operator">/</span>sdk<span class="operator">/</span><span class="keyword">default</span><span class="operator">/</span>openharmony

 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtpim&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtconnectivity&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtvirtualkeyboard&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtwebengine&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsystems&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtlocation&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtgamepad&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtscript&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsensors&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtwebview&quot;</span>

 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opensource -confirm-license&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -platform macx-clang -xplatform oh-clang&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opengl es2 -opengles3 -no-dbus&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -device-option OHOS_ARCH=arm64-v8a&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -nomake tests -nomake examples&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -fontconfig -I /Users/&lt;username&gt;/Library/fontconfig/include -L /Users/&lt;username&gt;/Library/fontconfig/libs&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -openssl-runtime OPENSSL_INCDIR=/Users/&lt;username&gt;/Library/openssl/include&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} ${SKIP_MODULES}&quot;</span>

 cd qt5
 mkdir build <span class="operator">&amp;</span><span class="operator">&amp;</span> cd build
 <span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>configure ${BUILD_OPTIONS} <span class="operator">-</span>prefix <span class="operator">/</span>Users<span class="operator">/</span><span class="operator">&lt;</span>username<span class="operator">&gt;</span><span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="number">5.15.12</span><span class="operator">/</span>ohos18_arm64<span class="operator">-</span>v8a <span class="operator">-</span>recheck<span class="operator">-</span>all
 make <span class="operator">-</span>j$(sysctl <span class="operator">-</span>n hw<span class="operator">.</span>ncpu) <span class="operator">&amp;</span><span class="operator">&amp;</span> make install
</pre>
<div class="admonition note">
<p><b>Note: </b>请注意将`&lt;username&gt;`替换为您的实际用户名。</p>
</div>
<h2 id="linux-qt-for-openharmony-qt-52063c09"><b>在 Linux 中为 Qt for OpenHarmony 构建 Qt 库</b></h2>
<h3 id="linux-qt-for-openharmony-qt-52063c09-b6cc125c-12"><b>配置构建环境</b></h3>
<p>安装必要的依赖项：</p>
<pre class="cpp" translate="no">
 sudo apt<span class="operator">-</span>get install build<span class="operator">-</span>essential python
</pre>
<p>下载OpenHarmony SDK并配置OpenHarmony SDK环境变量，以便找到llvm工具、SDK头文件和库。 在终端中输入以下命令，设置环境变量：</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> OHOS_SDK_PATH<span class="operator">=</span><span class="operator">/</span>usr<span class="operator">/</span>local<span class="operator">/</span>command<span class="operator">-</span>line<span class="operator">-</span>tools<span class="operator">/</span>sdk<span class="operator">/</span><span class="keyword">default</span><span class="operator">/</span>openharmony
</pre>
<p>以下为目前尚未完成 OpenHarmony 平台适配的模块，需要在编译时排除：</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtpim&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtconnectivity&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtvirtualkeyboard&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtwebengine&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsystems&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtlocation&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtgamepad&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtscript&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsensors&quot;</span>
 <span class="keyword">export</span> skip_modules<span class="operator">=</span><span class="string">&quot;${skip_modules} -skip qtwebview&quot;</span>
</pre>
<p>配置编译参数：</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opensource -confirm-license&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -platform linux-g++ -xplatform oh-clang&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opengl es2 -opengles3 -no-dbus&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -device-option OHOS_ARCH=arm64-v8a&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -nomake tests -nomake examples&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} ${SKIP_MODULES}&quot;</span>
</pre>
<div class="admonition note">
<p><b>Note: </b>OHOS_ARCH=armeabi-v7a会编译32位Qt库，OHOS_ARCH=arm64-v8a会编译64位Qt库，OHOS_ARCH=x86-64会编译x86_64Qt库。</p>
</div>
<p>启用fontconfig支持，需要准备fontconfig库及其相关头文件：（此项为可选配置）</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span>${BUILD_OPTIONS} <span class="operator">-</span>fontconfig <span class="operator">-</span>I <span class="string">&quot;/usr/local/fontconfig/include&quot;</span> <span class="operator">-</span>L <span class="string">&quot;/usr/local/fontconfig/libs&quot;</span>
</pre>
<p>启用openssl支持，需要准备openssl相关头文件：（此项为可选配置）</p>
<pre class="cpp" translate="no">
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span>${BUILD_OPTIONS} <span class="operator">-</span>openssl<span class="operator">-</span>runtime OPENSSL_INCDIR<span class="operator">=</span><span class="string">&quot;/usr/local/openssl/include&quot;</span>
</pre>
<h3 id="linux-qt-for-openharmony-qt-52063c09-qt-for-openharmony-59ae5410-13"><b>构建 Qt for OpenHarmony</b></h3>
<ol class="1" type="1"><li>打开终端，进入Qt for OpenHarmony源码目录。<pre class="cpp" translate="no">
 cd qt5
</pre>
</li>
<li>创建构建目录,进入构建目录<pre class="cpp" translate="no">
 mkdir build <span class="operator">&amp;</span><span class="operator">&amp;</span> cd build
</pre>
</li>
<li>运行以下命令，开始构建Qt for OpenHarmony。<pre class="cpp" translate="no">
 @REM 执行配置脚本，引用之前设置的临时环境变量${BUILD_OPTIONS}

 <span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>configure ${BUILD_OPTIONS} <span class="operator">-</span>prefix <span class="operator">/</span>usr<span class="operator">/</span>local<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="number">5.15.12</span><span class="operator">/</span>ohos18_arm64<span class="operator">-</span>v8a <span class="operator">-</span>recheck<span class="operator">-</span>all
 make <span class="operator">-</span>j$(nproc) <span class="operator">&amp;</span><span class="operator">&amp;</span> make install
</pre>
<div class="admonition note">
<p><b>Note: </b>该命令启用多线程编译功能，其中`$(nproc)`变量表示系统支持的最大线程数。您可根据实际需求调整线程数。</p>
</div>
</li>
<li>编译完成后，Qt for OpenHarmony将安装在指定的路径`/usr/local/Qt/5.15.12/ohos18_arm64-v8a`下</li>
</ol>
<h3 id="linux-qt-for-openharmony-qt-52063c09-7b166c7f-14"><b>完整构建脚本参考</b></h3>
<pre class="cpp" translate="no">
 <span class="preprocessor">#!/bin/bash</span>
 <span class="keyword">export</span> OHOS_SDK_PATH<span class="operator">=</span><span class="operator">/</span>usr<span class="operator">/</span>local<span class="operator">/</span>command<span class="operator">-</span>line<span class="operator">-</span>tools<span class="operator">/</span>sdk<span class="operator">/</span><span class="keyword">default</span><span class="operator">/</span>openharmony

 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtpim&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtconnectivity&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtvirtualkeyboard&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtwebengine&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsystems&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtlocation&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtgamepad&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtscript&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtsensors&quot;</span>
 <span class="keyword">export</span> SKIP_MODULES<span class="operator">=</span><span class="string">&quot;${SKIP_MODULES} -skip qtwebview&quot;</span>

 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opensource -confirm-license&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -platform linux-g++ -xplatform oh-clang&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -opengl es2 -opengles3 -no-dbus&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -device-option OHOS_ARCH=arm64-v8a&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} -nomake tests -nomake examples&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span>${BUILD_OPTIONS} <span class="operator">-</span>fontconfig <span class="operator">-</span>I <span class="string">&quot;/usr/local/fontconfig/include&quot;</span> <span class="operator">-</span>L <span class="string">&quot;/usr/local/fontconfig/libs&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span>${BUILD_OPTIONS} <span class="operator">-</span>openssl<span class="operator">-</span>runtime OPENSSL_INCDIR<span class="operator">=</span><span class="string">&quot;/usr/local/openssl/include&quot;</span>
 <span class="keyword">export</span> BUILD_OPTIONS<span class="operator">=</span><span class="string">&quot;${BUILD_OPTIONS} ${SKIP_MODULES}&quot;</span>

 cd qt5
 mkdir build <span class="operator">&amp;</span><span class="operator">&amp;</span> cd build
 <span class="operator">.</span><span class="operator">.</span><span class="operator">/</span>configure ${BUILD_OPTIONS} <span class="operator">-</span>prefix <span class="operator">/</span>usr<span class="operator">/</span>local<span class="operator">/</span><span class="type">Qt</span><span class="operator">/</span><span class="number">5.15.12</span><span class="operator">/</span>ohos18_arm64<span class="operator">-</span>v8a <span class="operator">-</span>recheck<span class="operator">-</span>all
 make <span class="operator">-</span>j$(nproc) <span class="operator">&amp;</span><span class="operator">&amp;</span> make install
</pre>
<h2 id="qt-c585cfc6"><b>查阅更多编译配置信息，请参阅Qt官方文档</b></h2>
<ol class="1" type="1"><li><a href="https://doc.qt.io/qt-5/configure-options.html">Qt configure options</a></li>
<li><a href="https://doc.qt.io/qt-5/build-sources.html">Building Qt Sources</a></li>
<li><a href="https://wiki.qt.io/Building_Qt_5_from_Git">Building Qt 5 from Git</a></li>
</ol>
</div>
<!-- @@@build-qt-for-openharmony.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
    <p>
        &copy; 2025 ISoftStone Co. All rights reserved.<br>
        Base on <a href="https://doc.qt.io/qt-6.8/zh/01-qdoc-manual.html"> QDoc 6.8.3 </a>, 
        Last update on 2025-08-15.
    </p> </div>
</body>
</html>
